package com.cskaoyan.utils;

import java.util.Random;

/**
 * String工具类
 *
 * @Author: zhang
 * @Date: 2022/11/20 15:46
 * @Since: jdk1.8
 */
public class StringUtil {
    /**
     * 判断字符串是否为空
     *
     * @param str 要判断的字符串
     * @return boolean
     */
    public static boolean isEmpty(String str) {
        return str == null || "".equals(str);
    }

    /**
     * 生成随机字符串
     *
     * @param length 字符串的长度
     * @return 随机字符串
     */
    public static String getRandomNum(int length) {
        StringBuilder pool = new StringBuilder();
        for (int i = '0'; i < '9'; i++) {
            pool.append((char) i);
        }
        char[] chars = new char[length];
        Random random = new Random();
        for (int i = 0; i < chars.length; i++) {
            int index = random.nextInt(pool.length());
            chars[i] = pool.charAt(index);
        }
        return new String(chars);
    }
}
